package com.shycloud.mido.homework.controller;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.shycloud.mido.common.core.util.R;
import com.shycloud.mido.homework.api.entity.TestSharding;
import com.shycloud.mido.homework.service.TestShardingService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;

/**
 * @author Xiaoxing Yu
 * @date 2020/11/17 下午2:17
 **/

@Api(tags = "测试数据库分表分库")
@RestController
@AllArgsConstructor
@RequestMapping("/sharding")
public class TestShardingController {

	private TestShardingService testShardingService;

	/**
	 * 插入测试数据
	 *
	 * @param entity
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 2020/11/17 2:18 下午
	 */
	@PostMapping("addData")
	@ApiOperation("插入测试数据")
	public R addData(@RequestBody TestSharding entity) {
		return new R(testShardingService.add(entity));
	}

	/**
	 * 获取数据
	 *
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 2020/11/17 2:18 下午
	 */
	@GetMapping("/getData")
	@ApiOperation("获取数据")
	public R getData() {
		return new R(testShardingService.get());
	}

	/**
	 * 测试获取作业数据和JOIN COMPLATE表
	 *
	 * @return com.shycloud.mido.common.core.util.R
	 * @author xiaoxing.yu
	 * @date 2020/11/17 2:18 下午
	 */
	@GetMapping("/getSharding")
	@ApiOperation("获取数据")
	public R getShardingData(Integer musicId, Long homeworkId) {
		return testShardingService.getSharding(musicId, homeworkId);
	}

}
